#!/usr/bin/env bash
replay=false
while getopts r OPT; do
  case "$OPT" in
    r)
      replay=true
      ;;
  esac
done
shift "$(($OPTIND - 1))"
bench="$@"
statfile=m5out/stats.txt
if "$replay"; then
  ./run -a arm -g -- --caches -r 1 --restore-with-cpu=HPI
  awk '/^system.switch_cpus.numCycles /{ print $2 }' "$statfile"
else
  ./run -a arm -e 'init=/eval.sh - lkmc_eval="m5 checkpoint;m5 resetstats;'"$bench"';m5 exit"' -g
  awk '/^system.cpu.numCycles /{ print $2 }' "$statfile"
fi
